﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AntiObesity.Base;
using AntiObesity.Base.Managers;

namespace AntiObesity.Services
{
    public partial class RecordIntake : SecuredPage//, ICallbackEventHandler
    {
        public DateTime Date
        {
            get
            {
                if (String.IsNullOrEmpty(Request["date"]))
                    return DateTime.Today;
                return Convert.ToDateTime(Request["date"]);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");
            //String callbackScript = "function CallServer(arg, context)" + "{ " + cbReference + ";}";
            //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", callbackScript, true);

            DataBind();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var intake = new Intake();
            // TODO: server side validations
            intake.UserID = Session.GetCurrentUser().ID;
            intake.FoodID = FoodManager.FindByName(txtFoodName.Text).ID;
            intake.Quantity = (float)Convert.ToDouble(txtAmount.Text);
            intake.Date = Convert.ToDateTime(txtDate.Text);
            IntakeManager.Persist(intake);
        }

        //#region ICallbackEventHandler Members

        //public string GetCallbackResult()
        //{
        //    // no result
        //    return null;
        //}

        //public void RaiseCallbackEvent(string eventArgument)
        //{
        //    IntakeHistory1.Update(Convert.ToDateTime(eventArgument));
        //}

        //#endregion
    }
}
